#!/usr/bin/python
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
from twisted.protocols import basic

class Putter(Protocol):

    def connectionMade(self):
        self.factory.clients.append(self)
        #for c in self.factory.clients:
        #    c.transport.write(self.factory.clients.index(self))
        print "hello", self.factory.clients.index(self)

    def connectionLost(self, reason):
        for c in self.factory.clients:
            if c != self:
                c.transport.write(self.factory.clients.index(self))
        print "good bye", self.factory.clients.index(self)
        self.factory.clients.remove(self)

    def dataReceived(self, line):
        for c in self.factory.clients:
            c.transport.write(line)
        print line

f = Factory()
f.protocol = Putter
f.clients = []
reactor.listenTCP(1025, f)
reactor.run()
